package main.java.com.itlin.recursion;

public class E03BinarySearch {

    public static int search(int[] a, int target){
        return f(a,target,0,a.length - 1);


    }

    private static int f(int[] a, int target, int lo, int hi) {
        if (lo > hi) {
            return -1;
        }

        int m = (lo + hi) >>> 1;
        if (target < a[m]) {
            return f( a, target , lo , m - 1  );
        } else if (target > a[m]) {
            return f(a,target, lo , m + 1);
        }else {
            return m;
        }

    }
}
